package Web;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.classic.Session;

import basak.HibernateUtil;


public class FirstPageServlet extends HttpServlet {
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	String e_mail=req.getParameter("e-mail");
	String password=req.getParameter("Password");
	
	Session session=null;
	 
	try{
		session=HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		
		Query query=(Query) session.createQuery("Select e-mail from User");
	  
	    List <String> mailList=  new ArrayList<String>();
	    mailList=query.list();
	    boolean user;
	    for (String x:mailList ) {
	    	if(x==e_mail){ user=true;
	    	Query info_query=session.createQuery("Select u.password from User u  where e-mail=e_mail");
	    	List pass=info_query.list();
	    	if(password.equals(pass.get(0))){req.getRequestDispatcher("/HomePage.jsp").forward(req, resp);}}
	    	else
	    		{req.getRequestDispatcher("/index.jsp").forward(req, resp);
	    }}
	}
	catch(Exception Ex){
		
	}
	
	
	
		
	}
	

}
